package com.smartleanx.module.hrm.controller.admin.contracttype;

import com.smartleanx.module.infra.api.file.dto.FileRefRespDTO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;

import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.framework.excel.core.util.ExcelUtils;

import com.smartleanx.framework.operatelog.core.annotations.OperateLog;

import static com.smartleanx.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.smartleanx.module.hrm.controller.admin.contracttype.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.contracttype.ContractTypeDO;
import com.smartleanx.module.hrm.service.contracttype.ContractTypeService;

@Tag(name = "管理后台/员工pc - 标准合同库分类")
@RestController
@RequestMapping("/hrm/contract-type")
@Validated
public class ContractTypeController {

    @Resource
    private ContractTypeService contractTypeService;

    @GetMapping("/getTree")
    @Operation(summary = "获得标准合同库分类树形结构")
    public CommonResult<List<ContractTypeTreeListRespVo>> getContractTypeTreeList() {
        List<ContractTypeTreeListRespVo> contractTypeTreeList = contractTypeService.getContractTypeTreeList();
        return success(BeanUtils.toBean(contractTypeTreeList, ContractTypeTreeListRespVo.class));
    }

    @GetMapping("/getChildrenFile")
    @Operation(summary = "获取当前文档分类类型下所有文件")
    @Parameter(name = "id", description = "id", required = true)
    public CommonResult<List<FileRefRespDTO>> getChildrenFile(@RequestParam("id") Long id,@RequestParam("name") String name) {
        List<FileRefRespDTO> childrenFile = contractTypeService.getChildrenFile(id,name);
        return success(BeanUtils.toBean(childrenFile, FileRefRespDTO.class));
    }

    @PostMapping("/createContractFileRef")
    @Operation(summary = "新增文档库类型文件关联信息")
    @Parameter(name = "id", description = "id", required = true)
    public CommonResult<Boolean> createContractFileRef(@RequestBody ContractFileRefReqVo vo) {
        return success(contractTypeService.createContractFileRef(vo));
    }


}
